package main

import (
	"encoding/json"
	"google.golang.org/protobuf/encoding/protojson"
	"io"
	"log"
	"math/rand"
	"os"
	"sporttech-cup/pkg/myfitt"
)

func main() {
	sourceFile := "input.json"
	var source *os.File
	if f, err := os.Open(sourceFile); err != nil {
		log.Fatalf("Unable to read source %v\n%v\n", sourceFile, err)
	} else {
		defer f.Close()
		source = f
	}
	unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true, AllowPartial: true}
	if input, err := io.ReadAll(source); err != nil {
		log.Fatal(err)
	} else {
		dset := &myfitt.InputDataset{}
		if err := unmarshaler.Unmarshal([]byte(input), dset); err != nil {
			log.Fatalf("Invalid input data set format %v\n%v\n", err, string(input))
		}
		// Вместо реальной оценки генерируем случайные величины
		var result []float64
		for i := 0; i <= len(dset.Sessions); i++ {
			result = append(result, float64(rand.Int31n(100))/100.0)
		}
		if outdata, err := json.Marshal(result); err != nil {
			log.Fatalf("Invalid result %v\n", err)
		} else {
			_, _ = os.Stdout.Write(outdata)
			_, _ = os.Stdout.WriteString("\n")
		}
	}
}
